package com.southpark.demo.view.toolTips.dataToolTip
{
	import com.southpark.demo.control.events.navigation.AddPopUpEvent;
	import com.southpark.demo.interfaces.popUps.IUserLoginPopUp;
	import com.southpark.demo.view.BaseViewController;
	import com.southpark.demo.view.toolTips.dataToolTip.interfaces.IDataToolTipCtrl;
	import com.southpark.demo.view.toolTips.dataToolTip.interfaces.IDataToolTipUI;
	import com.southpark.demo.vo.data.DataItemVO;
	import com.southpark.framework.control.responders.IResponder;
	import com.southpark.framework.control.responders.ResponderFactory;
	
	
	public class DataToolTipCtrl extends BaseViewController implements IDataToolTipCtrl
	{		
		public function DataToolTipCtrl(view:IDataToolTipUI)
		{
			super();
			this.view = view;
		}
		
		/**
		 * IDataToolTipCtrl
		 */
		private var view:IDataToolTipUI;
		
		private var dataItem:DataItemVO;
		
		public function set data(value:Object):void
		{
			dataItem = value as DataItemVO;
		}



		public function action1():void
		{
			var responder:IResponder = ResponderFactory.createResponder(onAction1Success);
			var e:AddPopUpEvent = new AddPopUpEvent(AddPopUpEvent.ID,responder);
			e.popUpInterface = IUserLoginPopUp;
			e.dispatch();
		}
		
		private function onAction1Success(result:Object):void
		{
			var userLoginPopUp:IUserLoginPopUp = result as IUserLoginPopUp;
			userLoginPopUp.setUserName(dataItem.item1);
			
			view.hideToolTip();
		}



		public function action2():void
		{
			var responder:IResponder = ResponderFactory.createResponder(onAction2Success);
			var e:AddPopUpEvent = new AddPopUpEvent(AddPopUpEvent.ID,responder);
			e.popUpInterface = IUserLoginPopUp;
			e.dispatch();
		}
		
		private function onAction2Success(result:Object):void
		{
			var userLoginPopUp:IUserLoginPopUp = result as IUserLoginPopUp;
			userLoginPopUp.setUserName(dataItem.item2);
			
			view.hideToolTip();
		}
		
	}
}